001 /* 002 * Copyright 2004 Niclas Hedhman, DPML 003 * Copyright 2005 Stephen McConnell, DPML 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 014 * implied. 015 * 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 package net.dpml.transit.model; 021 022 import java.io.Serializable; 023 024 import net.dpml.transit.NullArgumentException; 025 026 /** 027 * A request identifier. 028 * 029 * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a> 030 * @version 1.0.0 031 */ 032 public final class RequestIdentifier implements Serializable 033 { 034 // ------------------------------------------------------------------------ 035 // static 036 // ------------------------------------------------------------------------ 037 038 /** 039 * Serial version identifier. 040 */ 041 static final long serialVersionUID = 1L; 042 043 /** 044 * Used in hashcode calculation. 045 */ 046 private static final int MAGIC_NUMBER = 72349724; 047 048 // ------------------------------------------------------------------------ 049 // state 050 // ------------------------------------------------------------------------ 051 052 /** 053 * The internet address. 054 */ 055 private final String m_address; 056 057 /** 058 * The port. 059 */ 060 private final int m_port; 061 062 /** 063 * The prompt. 064 */ 065 private final String m_prompt; 066 067 /** 068 * The protocol. 069 */ 070 private final String m_protocol; 071 072 /** 073 * The scheme. 074 */ 075 private final String m_scheme; 076 077 // ------------------------------------------------------------------------ 078 // constructor 079 // ------------------------------------------------------------------------ 080 081 /** 082 * Creation of a new request identifier. 083 * @param address the address 084 * @param port the port 085 * @param protocol the protocol 086 * @param scheme the scheme 087 * @param prompt the prompt 088 * @exception NullArgumentException if any of the address, protocol, scheme 089 * or prompt arguments is null. 090 */ 091 public RequestIdentifier( 092 String address, int port, String protocol, String scheme, String prompt ) 093 throws NullArgumentException 094 { 095 if( address == null ) 096 { 097 throw new NullArgumentException( "address" ); 098 } 099 if( protocol == null ) 100 { 101 throw new NullArgumentException( "protocol" ); 102 } 103 if( scheme == null ) 104 { 105 throw new NullArgumentException( "scheme" ); 106 } 107 if( prompt == null ) 108 { 109 throw new NullArgumentException( "prompt" ); 110 } 111 m_address = address; 112 m_port = port; 113 m_protocol = protocol; 114 m_prompt = prompt; 115 m_scheme = scheme; 116 } 117 118 // ------------------------------------------------------------------------ 119 // implementation 120 // ------------------------------------------------------------------------ 121 122 /** 123 * Test for equality. 124 * @param obj the object to test against 125 * @return true if this object is the same as the supplied object 126 */ 127 public boolean equals( Object obj ) 128 { 129 if( !( obj instanceof RequestIdentifier ) ) 130 { 131 return false; 132 } 133 RequestIdentifier other = (RequestIdentifier) obj; 134 135 if( m_port != other.m_port ) 136 { 137 return false; 138 } 139 140 if( !m_address.equals( other.m_address ) ) 141 { 142 return false; 143 } 144 if( !m_protocol.equals( other.m_protocol ) ) 145 { 146 return false; 147 } 148 if( !m_prompt.equals( other.m_prompt ) ) 149 { 150 return false; 151 } 152 if( !m_scheme.equals( other.m_scheme ) ) 153 { 154 return false; 155 } 156 return true; 157 } 158 159 /** 160 * Return the hascode for this instance. 161 * @return the hashcode 162 */ 163 public int hashCode() 164 { 165 int hash = MAGIC_NUMBER * m_port; 166 hash = hash ^ m_address.hashCode(); 167 hash = hash ^ m_protocol.hashCode(); 168 hash = hash ^ m_prompt.hashCode(); 169 hash = hash ^ m_scheme.hashCode(); 170 return hash; 171 } 172 173 /** 174 * Return the string representation of this instance. 175 * @return the string value 176 */ 177 public String toString() 178 { 179 StringBuffer b = new StringBuffer(); 180 b.append( "ID[ " ); 181 b.append( m_protocol ); 182 b.append( ", " ); 183 b.append( m_address ); 184 b.append( ", " ); 185 b.append( m_port ); 186 b.append( ", " ); 187 b.append( m_scheme ); 188 b.append( ", " ); 189 b.append( m_prompt ); 190 b.append( " ]" ); 191 return b.toString(); 192 } 193 } 194